﻿#include <iostream>
#include <assert.h>
#include <map>

#include "dynamiccreate.h"

/////////////////////////////////////////////////

class Test
{
public:
    Test()
    {
        std::cout << "Create Test" << std::endl;
    }
};
REG_DYNCREATE(Test);

class Shape
{
public:
    virtual void Draw() = 0;
    virtual ~Shape() {}
};


class Circle : public Shape
{
public:
    void Draw()
    {
        std::cout << "Circle" << std::endl;
    }
    ~Circle(){};
};
REG_DYNCREATE(Circle, Shape);

class Square : public Shape
{
public:
    void Draw()
    {
        std::cout << "Square" << std::endl;
    }
    ~Square(){};
};
REG_DYNCREATE(Square, Shape);

class Rectangle : public Shape
{
public:
     void Draw()
    {
        std::cout << "Rectangle" << std::endl;
    }
    ~Rectangle(){};
};
REG_DYNCREATE(Rectangle, Shape);


//动态创建
int main()
{
    std::cout << "开始" << std::endl;
   
    Shape *ps;
    ps = static_cast<Shape *>(DYN_CREATE("Circle"));
    ps->Draw();
    delete ps;
 
    ps = static_cast<Shape *>(DYN_CREATE("Square"));
    ps->Draw();
    delete ps;
 
    ps = static_cast<Shape *>(DYN_CREATE("Rectangle"));
    ps->Draw();
    delete ps;


    auto ptr = static_cast<Test *>(DYN_CREATE("Test"));

    if(CRuntimeClassAgent::get_instance().IsBaseOf("Shape", "Square"))
    {
        std::cout << "shape is base of Square" << std::endl;
    }
        
    return 0;
}